class Node{
    public int key;
    public int val;
    public Node next;
    public Node(int key,int val){
        this.key=key;
        this.val=val;
    }
}
public class HashBuck {
    public Node[]array;
    public int usedSize;
    public HashBuck(){
        this.array=new Node[10];
    }

    public static final double DEFAULT_LOAD_FACTOR=0.75;
    public void put(int key,int val){
        int index=key%array.length;
        Node cur=array[index];
        while(cur!=null){
            if(cur.key==key){
                cur.val=val;
                return;
            }
            cur=cur.next;
        }
        Node node=new Node(key,val);
        node.next=array[index];
        array[index]=node;
        usedSize++;
        if(loadFactor()>=DEFAULT_LOAD_FACTOR){
            resize();
        }
    }

    public double loadFactor(){
        return  1.0*usedSize/array.length;
    }

    public void resize(){
        Node []newArray=new Node[2*array.length];
        for (int i = 0; i < array.length; i++) {
            Node cur=array[i];
            while(cur!=null){
                int index=cur.val%newArray.length;
                Node curNext=cur.next;
                cur.next=newArray[index];
                newArray[index]=cur;
                cur=curNext;
            }

        }
        array=newArray;
    }

    public int get(int key){
        int index=key%array.length;
        Node cur=array[index];
        while(cur!=null){
            if(cur.key==key){
                return cur.val;
            }
            cur=cur.next;
        }
        return -1;
    }

    public static void main(String[] args) {
        HashBuck hashBuck=new HashBuck();
        hashBuck.put(1,1);
        hashBuck.put(2,2);
        hashBuck.put(30,30);
        hashBuck.put(20,20);
        hashBuck.put(0,0);
        hashBuck.put(11,11);
        System.out.println("---");
    }
}
